﻿using StudySystem.MainLogic.FormControl;
using StudySystem.MainLogic.Items;
using StudySystem.Windows;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace StudySystem
{
    public partial class FormQuestions : Form
    {
        //记录当前界面打开的是哪个学科
        ClassSubject subject;
        List<ClassQuestion> questions;
        public FormQuestions()
        {
            InitializeComponent();
        }
        public FormQuestions(ClassSubject s)
        {
            InitializeComponent();
            subject = s;
            questions = s.Questions;
        }

        private void FormQuestions_Load(object sender, EventArgs e)
        {
            FormQuesControl.ShowQuestions(this.GetFlow(), questions);
        }

        private void btnAddQues_Click(object sender, EventArgs e)
        {
            bool result = FormController.CheckQuestion(rtbQuestion.Text, rtbAnswer.Text);
            if(result)
            {
                ClassQuestion.InsertAQuestion(subject.SubjectID, rtbQuestion.Text, rtbAnswer.Text);
                questions = subject.GetAllQuestion();//更新数据
                FormQuesControl.RenewQuestion(this.GetFlow(), questions);
                rtbQuestion.Text = "";
                rtbAnswer.Text = "";
                MessageBox.Show("问题添加成功！");
            }
            else
            {
                MessageBox.Show("未检测到有效内容，请重新输入！");
            }
        }

        private void btnSubmitRecord_Click(object sender, EventArgs e)
        {
            FormQuesControl.SubmitRecords(this.flpQuestions);
            MessageBox.Show("已提交所有答题记录！");
        }

        private void btnShowQues_Click(object sender, EventArgs e)
        {
            foreach (Question q in this.flpQuestions.Controls)
            {
                FormController.TxtShowControl(AnswerState.Show, q.richTxtAnswer, q.Ques.Answer);
            }
        }

        private void btnHideQues_Click(object sender, EventArgs e)
        {
            foreach (Question q in this.flpQuestions.Controls)
            {
                FormController.TxtShowControl(AnswerState.Hide, q.richTxtAnswer, q.Ques.Answer);
            }
        }
    }
}
